<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>三联物料BOM报表</title>
</head>
<body>
	<div style="height:50px;background-color: #F2F2F2">
		<div style="width:350px;height: 50px;;line-height:50px;margin: 0px auto;font-size: 30px;">
			<p style="padding: 0px;margin: 0px">三联物料BOM报表</p>
		</div>
	</div>
	
	<div style="height:100px;background-color: #F2F2F2">
		<div id="threeBOM_search_div" style="text-align:center; width:600px;height: 30px;line-height:30px;margin: 10px auto;font-size: 20px;">
			<input id="threeBOM_search_input_pkOrg"  data-options="label:'组织',labelWidth:'60'" type="text" style="width:280px;float: left;">
			<span id="threeBOM_search_code_span">
				<input id="threeBOM_search_input_code" class="easyui-textbox" data-options="label:'物料编码',labelWidth:'100',prompt:'请填入正确的物料编码'" type="text" style="width:280px;float: left;">
			</span>
			<span id="threeBOM_search_tagbox_span" style="margin-top: 50px">
				<input id="threeBOM_search_input_tagbox"  style="width: 500px">
                 <a id="oneBom_table_div_btnExport" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-back'">导出</a>
			</span>

		</div>
	</div>
	<div style="background-color: #F2F2F2">
	<div id="threeBOM_div_btn" style="width:220px;height:30px; margin: 0px auto;">
		<div style="float: left">
			<input id="fileNamePath" style="display: none" type="file" name="fileNamePath">

		</div>
	</div>
	</div>
	<div style="height:700px; width: 100%; border: #0E2D5F solid 1px">
		<div id="threeBOM_tabs" class="easyui-tabs" style="width: 100%;height:660px; float: left;" title="BOM详情"></div>
	</div>

	<script type="text/javascript">
		var threeBOMSearchInputTagbox;
		var threeBOMSearchInputPkOrg;
		var threeBOMSearchInputCode;
		var selectiveBom=[];    //选择的BOM
		var threeBOMTabs=$("#threeBOM_tabs").tabs({
			onClose:function (title,index) {//关闭选项卡触发

				if(selectiveBom.length>0){
					removeArrayByValue(selectiveBom,title);
				}
			},
			onAdd:function (title,index) {//添加选项卡触发
				selectiveBom.push(title);
			}
		});
		//$("#threeBOM_search_code_span").hide();
		$("#threeBOM_search_tagbox_span").hide();

		$("#oneBom_table_div_btnExport").linkbutton({
			onClick:function() {
				//首先获取需要导出的bom
				console.log(selectiveBom);
				var size = selectiveBom.length;
				if(size>0){
					$.messager.confirm('导出请求','您确认想要导出这<span style="color:red;">'+selectiveBom+'</span>BOM吗？',function(rr){
						if (rr){
							if(size>0){
								window.open('/reportForms/printBom?BOMs=' + selectiveBom);
								// var aDom = document.createElement('a');
								// aDom.href = '/reportForms/printBom?BOMs=' + selectiveBom;
								// aDom.click();
							}
						}
					});

				}else {
					topCommonMessage("还是要选择一下要导出的BOM联的");
				}
			}
		});

		$(function () {
			threeBOMSearchInputPkOrg=$("#threeBOM_search_input_pkOrg").combobox({
				valueField:'pkFactory',
				textField:'name',
				url:'/reportForms/getPkFactory',
				method:'post',
				prompt:'请选择组织',
				onSelect:function (record) {
					$("#threeBOM_search_code_span").show("normal","linear");
				}
			});

			//打开选项卡
			threeBOMSearchInputTagbox=$("#threeBOM_search_input_tagbox").tagbox({
				textField:'key',
				valueField:'value',
				hasDownArrow:true,
				labelPosition:'top',
				labelAlign:'center',
				prompt:'请选择要预览的BOM',
				data:[
					{value: '/reportForms/oneBOM.html',key: '第一联'},
					{value: '/reportForms/twoBOM.html',key: '第二联'},
					{value: '/reportForms/threeBOM.html',key: '第三联'}
				],
				onClickTag:function(value){ // 用户点击框内触发
					threeBOMTabs.tabs("select",getTabsName(value));
				},
				onRemoveTag:function(value){ //用户点击框内X触发
					threeBOMTabs.tabs("close",getTabsName(value));
				},
				onClick:function (record) {
					openTabs(threeBOMTabs,record.key,record.value);
				}
			})
			//判断是否有物料
			threeBOMSearchInputCode=$("#threeBOM_search_input_code").textbox({
				value:'N313000249',
				onChange:function (BOMCode) {
					$.ajax({
						method:'post',
						url:'/reportForms/getBdMaterialByCode',
						data:{"code":BOMCode},
						success:function (message) {
							if(message.statu==200){
								threeBOMSearchInputTagbox.tagbox({'label':message.data.name});
								$("#threeBOM_search_tagbox_span").show();
							}else if (message.statu==404){
								warnSessionConfirm();
							}else{
								topCommonMessage(message.message);
								$("#threeBOM_search_tagbox_span").hide();
							}
							closeTabs(threeBOMTabs,"第一联");
							closeTabs(threeBOMTabs,"第二联");
							closeTabs(threeBOMTabs,"第三联");
						},
						dataType:'json'
					})

				}
			})
		})

		//选项卡获取名字
		function getTabsName(value){
			var tabsName;
			if (value=='/reportForms/oneBOM.html') {
				tabsName='第一联';
			}else if (value=='/reportForms/twoBOM.html') {
				tabsName='第二联';
			}else{
				tabsName='第三联';
			}
			return tabsName;
		}
		//打印功能
        function printBom(content){
			$("#"+content).print({
				globalStyles:true,//是否包含父文档的样式，默认为true
				mediaPrint:false,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
				stylesheet:null,//外部样式表的URL地址，默认为null
				noPrintSelector:".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
				iframe:true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
				append:null,//将内容添加到打印内容的后面
				prepend:null,//将内容添加到打印内容的前面，可以用来作为要打印内容
				deferred:
						$.Deferred()//回调函数
			});
        }
	</script>

</body>
</html>